package com.squid.cloud.common.enums;

import org.codehaus.jackson.annotate.JsonValue;

public enum OpenEnum {
    //普票
    ALONE_COMMON("ALONE_COMMON","COMMON", "普票","个人普票"),
    COMPANY_COMMON("COMPANY_COMMON","COMMON","普票","企业普票"),
    //专票
    COMPANY_SPECIAL("COMPANY_SPECIAL","SPECIAL","专票","企业专票"),
    ALONE_SPECIAL("ALONE_SPECIAL","SPECIAL", "专票", "个人专票");
    private String code;

    private String group;

    private String groupName;

    private String codeName;

    /**
     * 通过编号获取枚举
     * @param code
     * @return
     */
    public static OpenEnum getEnumByCode(String code) {
        for (OpenEnum c : OpenEnum.values()) {
            if (c.code.equals(code)) {
                return c;
            }
        }

        return null;
    }

    private OpenEnum(String code, String group, String groupName, String codeName){
        this.code = code;
        this.group = group;
        this.groupName = groupName;
        this.codeName = codeName;
    }

    public static OpenEnum groupValueOf(String group){
        OpenEnum[] openEnums = OpenEnum.values();
        for (OpenEnum openEnum : openEnums){
            if (openEnum.group.equals(group)){
                return openEnum;
            }
        }
       throw new IllegalArgumentException("枚举分组值:" + group + "不存在,请核对后在试");
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getGroup() {
        return group;
    }

    public void setGroup(String group) {
        this.group = group;
    }

    @JsonValue
    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    @JsonValue
    public String getCodeName() {
        return codeName;
    }

    public void setCodeName(String codeName) {
        this.codeName = codeName;
    }
}
